package com.shop.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.shop.entity.Shopringcart;
import com.shop.shop.mapper.ShopringcartMapper;
import com.shop.shop.service.CommodityService;
import com.shop.shop.service.ShopringcartService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.shop.utile.MapUtile;
import com.shop.shop.utile.PageUtile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小🌤
 * @since 2021-05-05
 */
@Service
public class ShopringcartServiceImpl extends ServiceImpl<ShopringcartMapper, Shopringcart> implements ShopringcartService {
     @Autowired
     private CommodityService commodityService;

    @Override
    public Map<String, Object> findPage(MapUtile mapUtile, Integer userId) {
        Map<String,Object> masp=new HashMap<>();
        QueryWrapper<Shopringcart> wrapper=new QueryWrapper<>();
        wrapper.eq("ur_id",userId);
        Page<Shopringcart> page = new PageUtile<Shopringcart>().getPage(mapUtile);
        baseMapper.selectPage(page,wrapper);
        List<Shopringcart> list = page.getRecords();
        list.forEach(shopringcart->{
            //查询商品信息
              shopringcart.setCommodity(commodityService.getById(shopringcart.getCmId()));
        });

        masp.put("list", list);
        masp.put("pages", page.getPages());
        masp.put("size", page.getSize());
        masp.put("page", page.getCurrent());
        masp.put("total", page.getTotal());
        return masp;
    }
}
